import Vue from 'vue'
//import App from './pages/app.vue'
import routerApp from './pages/routerApp.vue'
import VueRouter from 'vue-router'
import { userInfo } from 'os';


Vue.use(VueRouter);     //加载插件

//创建路由列表
const Routers=[
    {
        path:'/index',  //路由关键字
        meta:{title:'首页'},
        component:(resolve)=>require(['./pages/routerTest/index.vue'],resolve)  //懒加载
    },
    {
        path:'/about',
        meta:{title:'关于'},
        component:(resolve)=>require(['./pages/routerTest/about.vue'],resolve)
    },
    {
        path:'/user/:id',
        meta:{title:'个人主页'},
        component:(resolve)=>require(['./pages/routerTest/user.vue'],resolve)
    },
    {
        path:'*',
        redirect:'/index'
    }
];

const RouterConfig={
    mode:'history',     //SPA的实现机制设定，有history和hash两种选择，对package.json中dev命令加上--history-api-fallback
    routes:Routers      //指定路由列表
}
const router = new VueRouter(RouterConfig); //创建路由
router.beforeEach((to,from,next)=>{
    window.document.title=to.meta.title;
    next();
});

new Vue({
    el:"#app",
    router:router,      //加载路由
    render:h=>h(routerApp)
});